
function package(c, list) {
  function _package(i, rest) {
    if (i > list.length) {
      return 0
    }
    var product = list[i]
    if (product.v > rest) {
      return _package(i + 1, rest)
    } else {
      var select = product.p + _package(i + 1, rest - product.v)
      var notSelect = _package(i + 1, rest)
      return Math.max(select, notSelect)
    }
  }
  return _package(0, c)

}
var c = 40;
var list = [
  { v: 10, p: 5 },
  { v: 7, p: 4 },
  { v: 11, p: 8 },
  { v: 9, p: 6 },
  { v: 2, p: 1 },
  { v: 17, p: 20 },
  { v: 25, p: 30 },
];
var res = package(c, list);
console.log(res)
